/* 
 * StikiWeb Wiki - a Wiki for Hierarchical Organizations
 * $Id: AdminBean.java,v 1.4 2004/05/07 14:58:10 biglee Exp $
 * 
 * ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is the StikiWeb Wiki.
 *
 * The Initial Developer of the Original Code is Lee Haslup (biglee@haslups.com).
 * Portions created by the Initial Developer are Copyright (C) 2004
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
 * ***** END LICENSE BLOCK ***** 
 */
package org.stikiweb.struts;

import java.util.ArrayList;

import org.apache.struts.action.ActionForm;

/**
 * @author Allen L (BigLee) Haslup
 *
 */
public class AdminBean extends ActionForm {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -4110536265226566837L;

	// ========================================
	// Constructor -- ensures that collections are available
	// ========================================
	public AdminBean() {
		this.users = new StrutsFriendlyMagicSelfGrowingArrayList(UserPermBean.class);
		this.availableUsers = new StrutsFriendlyMagicSelfGrowingArrayList(AvailUserBean.class);
		this.adminChildren = new StrutsFriendlyMagicSelfGrowingArrayList(AdminChildBean.class);
	}
	
	// ==================================================
	// newRecord - non empty if this page has no current page record.
	// ==================================================
	private String newRecord;
	
	public String getNewRecord() {
		return newRecord;
	}
	
	public void setNewRecord(String value) {
		newRecord = value;
	}
	
	public void setNewRecord(boolean value) {
		if(value) newRecord = "Y";
		else newRecord = "";
	}
	
	// ==================================================
	// resetBean property - set if we have forwarded to a different page
	// ==================================================
	private String resetBean;

	// ==============================================
	// users property - a nested list of UserPermBeans
	// ==============================================

	// users appearing on permission list (ArrayList of UserPermBeans)
	private ArrayList users;
	

	public ArrayList getUsers() {
		return users;
	}

	public void setUsers(ArrayList list) {
		users = list;
	}
	
	public void addUserPermBean(UserPermBean userPermBean) {
		users.add(userPermBean);
	}
	
	public int getUserPermBeanIndex(UserPermBean userPermBean) {
		return users.indexOf(userPermBean);
	}
	
	public UserPermBean getUsers(int index) {
		while(users.size()<=index) {
			addUserPermBean(new UserPermBean());
		}
		return (UserPermBean)(users.get(index));
	}
	
	// ==============================================
	// availableUsers property - a nested list of AvailUserBeans
	// ==============================================

	// user ids available for pick list  (Vector of UserPermBeans)
	private ArrayList availableUsers;
	

	public ArrayList getAvailableUsers() {
		return availableUsers;
	}

	public void setAvailableUsers(ArrayList list) {
		availableUsers = list;
	}
	
	public void addAvailUserBean(AvailUserBean availUserBean) {
		availableUsers.add(availUserBean);
	}
	
	public int getAvailUserBeanIndex(AvailUserBean availUserBean) {
		return availableUsers.indexOf(availUserBean);
	}
	
	public AvailUserBean getAvailableUsers(int index) {
		while(availableUsers.size()<=index) {
			addAvailUserBean(new AvailUserBean());
		}
		return (AvailUserBean)(availableUsers.get(index));
	}
	
	// ===============================================
	// childPages property - nested list of names of admin children
	// ===============================================
	
	// List of administered children of this page.
	private ArrayList adminChildren;
	
	
	public String getHasAdminChildren() {
		return (adminChildren.size()==0)?null:"Yes";
	}
	
	public ArrayList getAdminChildren() {
		return adminChildren;
	}
	
	public void setAdminChildren(ArrayList list) {
		adminChildren=list;
	}
	
	public void addAdminChildBean(AdminChildBean adminChildBean) {
		adminChildren.add(adminChildBean);
	}
	
	public int getAdminChildBeanIndex(AdminChildBean adminChildBean) {
		return adminChildren.indexOf(adminChildBean);
	}
	
	public AdminChildBean getAdminChildren(int index) {
		while(adminChildren.size()<=index) {
			addAdminChildBean(new AdminChildBean());
		}
		return (AdminChildBean)(adminChildren.get(index));
	}

	// ============================================
	// name property - name of the page being administered
	// ============================================
	private String name;

	public String getName() {
		return name;
	}

	public void setName(String string) {
		name = string;
	}
	
	// ==============================================
	// adminParent property - name of admin parent page
	// ==============================================
	
	private String adminParent;
	
	public String getAdminParent() {
		return adminParent;
	}

	public void setAdminParent(String string) {
		adminParent = string;
	}
	
	// set to "Yes" if this user has admin level perm for parent page.
	private String canAdminParent;
	
	public String getCanAdminParent() {
		return canAdminParent;
	}
	public void setCanAdminParent(String string) {
		canAdminParent = string;
	}

	// ==================================================
	// newUserId  property - user id for user to be added to perm list
	// ==================================================

	private String newUserId;

	public String getNewUserId() {
		return newUserId;
	}

	public void setNewUserId(String string) {
		newUserId = string;
	}

	// ==================================================
	// newUserPerm  property - Perm level for new perm list user 
	// ==================================================

	private String newUserPerm;

	public String getNewUserPerm() {
		return newUserPerm;
	}
	
	public void setNewUserPerm(String string) {
		newUserPerm = string;
	}
	
	// ======================================
	// maxStorage property - limit size of page storage
	// ======================================
	
	// number of bytes (/100k) this page is allowed to contain.
	// for instance, 50 = 5 meg, 5=1/2 meg.
	private String maxStorage;

	public String getMaxStorage() {
		return maxStorage;
	}

	public void setMaxStorage(String string) {
		maxStorage = string;
	}
	
	// ==========================================
	// reservedStorage property - is max space guaranteed?
	// ==========================================
	
	// non-empty if parent page reserves max storage for this page.
	private String reservedStorage;

	public String getReservedStorage() {
		return reservedStorage;
	}

	public void setReservedStorage(String string) {
		reservedStorage = string;
	}
	
	// =======================================================
	// availableStorage property - how much space is available
	// =======================================================
	
	// storage availabl in bytes
	private String availableStorage;
	
	public String getAvailableStorage() {
		return availableStorage;
	}
	
	public void setAvailableStorage(String string) {
		availableStorage = string;
	}
	
	// ===========================================================
	// storageUsed property - how much storage does this page use
	// ===========================================================
	
	// storage used by this page and its attachments plus the sum of
	// the storage used or reserved by its children.
	private String storageUsed;
	
	public String getStorageUsed() {
		return storageUsed;
	}
	
	public void setStorageUsed(String string) {
		storageUsed = string;
	}
	
	
	// ==============================================
	// maxSizePerAttachment property - largest legal attachment
	// ==============================================
	
	// the size (/100k) of the largest attachment that can be saved
	private String maxSizePerAttachment;

	public String getMaxSizePerAttachment() {
		return maxSizePerAttachment;
	}

	public void setMaxSizePerAttachment(String string) {
		maxSizePerAttachment = string;
	}
	
	// ==============================================
	// template property - template to use for this and child pages
	// ==============================================

	private String templateName;
	
	public String getTemplateName() {
		return templateName;	
	}
	
	public void setTemplateName(String string) {
		templateName = string;
	}
	
	// =====================================================
	// selectedChild property - admin child selected for new admin screen
	// =====================================================
	
	// child user wants to administer when he presses "go to child" button
	private String selectedChild;
	
	public String getSelectedChild() {
		return selectedChild;
	}

	public void setSelectedChild(String string) {
		selectedChild = string;
	}

	// ======================
	// properties for button values
	// ======================
	
	// non-empty if user pressed the APPLY button
	private String apply;
	
	public String getApply() {
		return apply;
	}
	
	public void setApply(String string) {
		apply = string;
	}
	
	// non-empty if user pressed the SAVE button
	private String save;

	public String getSave() {
		return save;
	}

	public void setSave(String string) {
		save = string;
	}
	
	// non-empty if user pressed the CANCEL button
	private String cancel;

	public String getCancel() {
		return cancel;
	}

	public void setCancel(String string) {
		cancel = string;
	}

	// non-empty if user wants to go administer the parent
	public String goToParent;

	public String getGoToParent() {
		return goToParent;
	}

	public void setGoToParent(String string) {
		goToParent = string;
	}
	
	// non-empty if user wants to go administer the parent
	public String goToChild;

	public String getGoToChild() {
		return goToChild;
	}

	public void setGoToChild(String string) {
		goToChild = string;
	}

	/**
	 * @return
	 */
	public String getResetBean() {
		return resetBean;
	}

	/**
	 * @param string
	 */
	public void setResetBean(String string) {
		resetBean = string;
	}

}
